package com.hzhr.iot.collect.dao;

import com.hzhr.iot.collect.dao.mapper.custom.CommandCountEntityCustomMapper;
import com.hzhr.iot.collect.dao.mapper.generator.CommandCountEntityMapper;
import com.hzhr.iot.collect.entity.CommandCountEntity;
import com.hzhr.iot.collect.entity.ext.CommandCountEntityExt;
import com.hzhr.iot.collect.queryModel.custom.CommandCountCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class CommandCountDao {
    @Autowired
    CommandCountEntityMapper commandCountEntityMapper;
    @Autowired
    CommandCountEntityCustomMapper commandCountEntityCustomMapper;

    public int insert(CommandCountEntity record) {
        if (record == null) return 0;
        int changeCount = commandCountEntityMapper.insert(record);
        return changeCount;
    }

    public int delete(CommandCountCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = commandCountEntityCustomMapper.delete(queryModel);
        return changeCount;
    }

    public int update(CommandCountEntity record) {
        if (record == null) return 0;
        int changeCount = commandCountEntityMapper.updateByPrimaryKey(record);
        return changeCount;
    }

    public int updateProps(CommandCountCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = commandCountEntityCustomMapper.updateProps(queryModel);
        return changeCount;
    }

    public CommandCountEntity selectEntity(CommandCountCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<CommandCountEntityExt> extList = commandCountEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<CommandCountEntity> selectEntityList(CommandCountCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<CommandCountEntityExt> extList = commandCountEntityCustomMapper.selectExt(queryModel);
        if (extList == null) return null;
        List<CommandCountEntity> entityList = new ArrayList<>();
        for (CommandCountEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }
    public CommandCountEntityExt selectExt(CommandCountCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<CommandCountEntityExt> extList = commandCountEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<CommandCountEntityExt> selectExtList(CommandCountCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<CommandCountEntityExt> extList = commandCountEntityCustomMapper.selectExt(queryModel);
        return extList;
    }

    public int selectCount(CommandCountCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = commandCountEntityCustomMapper.selectCount(queryModel);
        return count;
    }
}
